package com.hnevc.jsondemo;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2017/11/20.
 */

public class MyAdapter extends BaseAdapter{
    List<Food> mFoodList;
    Context mContext;

    public MyAdapter(List<Food> mFoodList,Context mContext) {
        this.mFoodList = mFoodList;
        this.mContext=mContext;
    }

    //返回要显示的数据项的数目
    @Override
    public int getCount() {
        return mFoodList.size();
    }

    //返回第position位置的数据项
    @Override
    public Object getItem(int position) {
        return mFoodList.get(position);
    }

    //返回position位置的数据项的关键字id
    @Override
    public long getItemId(int position) {
        return mFoodList.get(position).getFoodId();
    }

    //返回position位置的显示的视图
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view=View.inflate(mContext,R.layout.list_item,null);
        ImageView imageView=(ImageView) view.findViewById(R.id.id_iv_food_pic);
        TextView textView=(TextView)view.findViewById(R.id.id_tv_food_name);
        textView.setText(mFoodList.get(position).getFoodName());
        return view;
    }
}
